﻿using System;
using System.Data;
using System.Text.RegularExpressions;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Housing;
using System.Data.SqlClient;

public partial class StreetCenter_AddApply : System.Web.UI.Page
{
    public string disableCSS="";
    protected void Page_Load(object sender, EventArgs e)
    {

        //Session["UserId"] = "6";
        //Session["UserName"] = "ximen";
        //Session["UserType"] = "辖区房管所";
        //Session["UserStreet"] = "西门";
        this.thetype.Value = Request.QueryString["thetype"];
        
        if (Session["UserStreet"] == null)
            WebHelper.AlertAndRedirect("登陆超时，请重新登陆", "../Login.aspx");
        else
        {
            this.setSysConfig();
            if (!IsPostBack)//修改提交不处理
            {
                if (!String.IsNullOrEmpty(Request.QueryString["applyid"]) && Regex.IsMatch(Request.QueryString["applyid"], @"^-?\d+$"))
                {
                    lblid.Text = Request.QueryString["applyid"].ToString();
                }
                switch (Request.QueryString["thetype"])
                {
                    case "view":
                        tdEditNote.Visible = true;
                        this.btnDel.Visible = false;
                        this.HyperLink2.Visible = true;
                        btnedit.Visible = false;
                        this.HyperLink1.Visible = true;
                        this.disableCSS = @" <style>   
                                              
                                              input{qswh:expression(this.disabled=true)}   
                                              textarea{qswh:expression(this.disabled=true)}   
                                              select{qswh:expression(this.disabled=true)}   
                                              input.enable{qswh:expression(this.disabled=false)}   
                                               
                                              </style>";
                        btnapply.Visible = false;
                        if (!String.IsNullOrEmpty(Request.QueryString["applyid"]) && Regex.IsMatch(Request.QueryString["applyid"], @"^-?\d+$"))
                        {
                            _applyid = Request.QueryString["applyid"];
                            ShowDataByApplyID(Request.QueryString["applyid"]);
                            this.HyperLink1.NavigateUrl = "AddApply.aspx?applyid=" + _applyid + "&thetype=edit";
                            this.HyperLink2.NavigateUrl = "AddApply.aspx?applyid=" + _applyid + "&thetype=edit";
                        }
                        else
                            WebHelper.AlertAndClose("参数applyid出错");

                        break;
                    case "edit":
                        tdEditNote.Visible = false;
                        this.btnDel.Visible = true;
                        this.HyperLink2.Visible = false;
                        this.HyperLink1.Visible = false;
                        btnedit.Text = "点击校对";
                        btnedit.Visible = true;
                        btnapply.Visible = false;
                        if (!String.IsNullOrEmpty(Request.QueryString["applyid"]) && Regex.IsMatch(Request.QueryString["applyid"], @"^-?\d+$"))
                        {
                            _applyid = Request.QueryString["applyid"];
                            ShowDataByApplyID(Request.QueryString["applyid"]);
                            //this.EffectDateYear.Enabled = false;
                            //this.EffectDateMonth.Enabled = false;
                        }
                        else
                            WebHelper.AlertAndClose("参数applyid出错");
                        break;
                    case "change":
                        HyperLink2.Visible = false;
                        tdEditNote.Visible = true;
                        btnedit.Visible = true;
                        btnapply.Visible = false;
                        btnedit.Text = "点击调整";
                        string efficedate = "";
                        if (Request.QueryString["effectdate"] != null)
                        { efficedate = Request.QueryString["effectdate"].ToString();}
                        else
                            WebHelper.AlertAndClose("参数effectdate出错");
                        this.EffectDateYear.SelectedValue = efficedate.Substring(0, 4);
                        if (!String.IsNullOrEmpty(Request.QueryString["applyid"]) && Regex.IsMatch(Request.QueryString["applyid"], @"^-?\d+$"))
                        {
                            _applyid = Request.QueryString["applyid"];
                            ShowDataByApplyID(Request.QueryString["applyid"]);

                        }
                        else
                            WebHelper.AlertAndClose("参数applyid出错");


                        if (efficedate.Substring(4, 1) == "0")
                        {                            
                            this.EffectDateMonth.SelectedValue = efficedate.Substring(5, 1);
                        }
                        else
                        { 
                            this.EffectDateMonth.SelectedValue = efficedate.Substring(4, 2);
                        }
                       
                        break;
                        
                    default:
                        if (Request["id"] != null && Session["UserId"] != null)
                        {
                            if (Apply.isExistNoID(Request["id"]))
                                WebHelper.AlertAndClose("已经存在该编号的审核表");
                            lblnoid.Text = Request.QueryString["id"].ToString();
                            this.EffectDateYear.Enabled = true;
                            this.EffectDateMonth.Enabled = true;

                        }
                        break;
                }
            }
        }
    }
    private string _applyid = "";
    protected void BindDocument()
    {
        Documents document = new Documents();
        SqlDataReader dr = document.GetAllDocuments();
        int i = 0;
        while (dr.Read())
        {
            rbldoc.Items.Insert(i, new ListItem(dr["doc_name"].ToString(), dr["doc_name"].ToString()));
            i++;
        }
        dr.Close();
    }
    private void setSysConfig()
    {
        BindDocument();
        BindDate();
        SystemItems systemitem = new SystemItems();
        systemitem.GetNewestSystemItem();
        if (systemitem != null)
        {
            //otherrentstandard = 1;   //租金补贴标准(最低收入、其他家庭)
            //lowrentstandard = 1;     //租金补贴标准(低收入)
            //onlyonearea = 0;         //租金补贴户面积（36㎡）
            //homeavgarea = 0;         //租金补贴比较面积(18㎡)
            //standardlowarea = 1;     //保障面积最低标准(5㎡)
            otherrentstandard.Value = systemitem.Sys_otherrentstandard;
            lowrentstandard.Value = systemitem.Sys_lowrentstandard;
            onlyonearea.Value = systemitem.Sys_onlyonearea;
            homeavgarea.Value = systemitem.Sys_avgarea;
            standardlowarea.Value = systemitem.Sys_standardlowarea;
        }
    }

    //修改读apply值
    public string OtherApplicant = "";
    public Apply EditApply = new Apply();
    public Property Property = new Property();
    //得到申请人家庭
    public string OtherApplicantHTML = "";
    //住房状况
    public string OtherHouseHTML = "";
    //住房总面积
    public float HouseTotalArea = 0;
    //保障人口
    public int ProNum = 1;
    //家庭人口
    public int FamilyNum = 1;



    //Edit
    private void ShowDataByApplyID(string applyid)
    {

        ProNum--;
        FamilyNum--;
        EditApply.SetApply(applyid);
        ViewState["apply"] = EditApply;
        //读取财产情况
        Property.SetProperty(applyid);
        txbaddress.Text = EditApply.apply_address;
        txbphone.Text = EditApply.apply_phone;
        this.tbCutSubsidyNum.Text = EditApply.CutSubsidyNum.ToString();
        this.tbAddSubsidyNum.Text = this.EditApply.AddSubsidyNum.ToString();
        if (EditApply.isLengthenAYear == 1)
            cbisLengthenAYear.Checked = true;
        if (!string.IsNullOrEmpty(EditApply.apply_docdate))
        {
            ddlyear4.SelectedValue = EditApply.apply_docdate.Substring(0, 4);
            if (EditApply.apply_docdate.Substring(4, 1) == "0")
                ddlmonth4.SelectedValue = EditApply.apply_docdate.Substring(5, 1);
            else
                ddlmonth4.SelectedValue = EditApply.apply_docdate.Substring(4, 2);
            txbproofnum.Text = EditApply.apply_docnum;
        }
        if (EditApply.apply_paybycard != "0")
        {
            chkcard.Checked = true;
            chkmoney.Checked = false;
            txbcardnum.Text = EditApply.apply_paybycard;
        }
        else
            chkmoney.Checked = true;
        //Response.Write(EditApply.EffectDate.ToString());
        //Response.End();

        if (!string.IsNullOrEmpty(EditApply.EffectDate.ToString()) && EditApply.EffectDate.ToString().Length ==6)
        {
            this.EffectDateYear.SelectedValue = EditApply.EffectDate.ToString().Substring(0, 4);
            this.EffectDateMonth.SelectedValue =int.Parse(EditApply.EffectDate.ToString().Substring(4, 2)).ToString();
        }
        else
            WebHelper.AlertAndClose("EffectDate不完整");
        lblnoid.Text = EditApply.apply_noid.ToString();
        txbapplytime.Text = Convert.ToDateTime(EditApply.apply_time).ToString("yyyy-MM-dd");
        apply_longid.Text = EditApply.apply_longid;
        //Response.Write(EditApply.apply_longid);
        //Response.End();
        tbEditNote.Text = EditApply.EditNote;


        //申请人家庭
        SqlDataReader drApplicant = new Applicant().GetApplicantByApplyid(this._applyid);
        int i = 0;
        int count = 0;
        while (drApplicant.Read())
        {
            if (drApplicant["app_ispro"].ToString() == "1")
            { ProNum++; }
            FamilyNum++;
            i++;
            if (i == 1)
            {
                //Response.Write(drApplicant["app_marryed"].ToString());
                ddlmarryed.SelectedValue = drApplicant["app_marryed"].ToString();
                txbname.Text = drApplicant["app_name"].ToString();
                txbunit.Text = drApplicant["app_workunit"].ToString();
                txbcard.Text = drApplicant["app_idcard"].ToString();
                txbincome.Text = drApplicant["app_income"].ToString();
                ckbispro.Checked = ((drApplicant["app_ispro"].ToString() == "1") ? true : false);

            }
            else
            {
                int marrySelectedIndex = 0;
                switch (drApplicant["app_marryed"].ToString())
                {
                    case "未婚": marrySelectedIndex = 0; break;
                    case "已婚": marrySelectedIndex = 1; break;
                    case "离婚": marrySelectedIndex = 2; break;
                    case "丧偶": marrySelectedIndex = 3; break;

                }
                OtherApplicantHTML += "<table width='100%' border='1' cellspacing='0' style='border-top:none; border-bottom:none; border-left:none; border-right:none'  id='AppNode" + count + "'>";
                OtherApplicantHTML += "<tr >" + Environment.NewLine;
                OtherApplicantHTML += "<td width='56px' height='50'><input type='text' name='txbapplytitle" + count + "' style='width:90%' class='UnderlineButton1' value='" + drApplicant["app_title"].ToString() + "'></td>" + Environment.NewLine;
                OtherApplicantHTML += "<td width='58px'><input type='text' name='txbname" + count + "' style='width:90%' class='UnderlineButton1' value='" + drApplicant["app_name"].ToString() + "'></td>" + Environment.NewLine;
                OtherApplicantHTML += "<td width='59px'><select name='ddlmarry" + count + "' ><option value='未婚'>未婚</option><option value='已婚'>已婚</option><option value='离婚'>离婚</option><option value='丧偶'>丧偶</option></select> <script>document.getElementById('ddlmarry" + count + "').selectedIndex=" + marrySelectedIndex.ToString() + "</script></td>" + Environment.NewLine;
                OtherApplicantHTML += "<td width='212px'><input type='text' name='txbunit" + count + "' style='width:90%' class='UnderlineButton1' value='" + drApplicant["app_workunit"].ToString() + "'></td>" + Environment.NewLine;
                OtherApplicantHTML += "<td width='214px'><input type='text' name='txbcard" + count + "' style='width:90%' class='UnderlineButton1' value='" + drApplicant["app_idcard"].ToString() + "'></td>" + Environment.NewLine;
                OtherApplicantHTML += "<td width='168px'><input type='text' name='txbincome" + count + "' style='width:90%' class='UnderlineButton1' value='" + drApplicant["app_income"].ToString() + "' onblur='Totleincome(\"txbincome" + count + "\",\"text_val" + count + "\");' onkeydown = 'DigitInput(this,event);'><input type='hidden' id='text_val" + count + "' value='" + drApplicant["app_income"].ToString() + "' /></td>" + Environment.NewLine;
                OtherApplicantHTML += "<td width='72px'>&nbsp;&nbsp;<input type='checkbox' id='ckbispro" + count + "' " + (drApplicant["app_ispro"].ToString() == "1" ? "checked" : "") + "   name='ckbispro" + count + "' onclick='CountIsproNum(\"ckbispro" + count + "\");Subsidy();' /></td>" + Environment.NewLine;

                OtherApplicantHTML += "<td width=\"38px\"><input type=\"button\" value=\"删除\" name=\"del" + count + "\" onclick=\"DelRowApplication(this)\");getTotal();Subsidy();\"/></td>";
                OtherApplicantHTML += "</tr></table>";

            }
            count++;
        }
        drApplicant.Close();
        //读取财产情况
        txbsecuritie.Text = Convert.ToString(Property.pro_securitie);
        txbestate.Text = Convert.ToString(Property.pro_estat);
        txbdevice.Text = Convert.ToString(Property.pro_device);
        txbothers.Text = Convert.ToString(Property.pro_other);

        //房屋情况
        int houcount = 0;
        int mmm = 1;
        float houseTotalArea = 0;
        SqlDataReader drhou = new HouseSituation().GetHouseSituationByapplyid(this._applyid);
        while (drhou.Read())
        {
            if (drhou["hou_addcounted"].ToString() == "1" && !Convert.IsDBNull(drhou["hou_area"].ToString()))
                HouseTotalArea += float.Parse(drhou["hou_area"].ToString());
            if (houcount == 0)
            {
                txblocal.Text = drhou["hou_address"].ToString();
                txbarea.Text = drhou["hou_area"].ToString();
                txbowner.Text = drhou["hou_owner"].ToString();
                txbownproof.Text = drhou["hou_ownproof"].ToString();
                txbnature.Text = drhou["hou_nature"].ToString();
                txbremark.Text = drhou["hou_remark"].ToString();
                ckbaddcount.Checked = drhou["hou_addcounted"].ToString() == "1" ? true : false;

            }
            else
            {
                OtherHouseHTML += "<table width='100%' border='1' cellspacing='0'  style='border-top:none; border-bottom:none; border-left:none; border-right:none' id='HousingNode" + houcount + "'>";
                OtherHouseHTML += "<tr>";
                OtherHouseHTML += "<td width='25px' style='height: 37px'>" + mmm + "&nbsp;</td>";
                OtherHouseHTML += "<td style='width:175px;height:37px;'><input type='text' name='txblocal" + houcount + "' value='" + drhou["hou_address"].ToString() + "' class='UnderlineButton1'  style='width:150px'></td>";
                OtherHouseHTML += "<td style='height:37px;width:80px;'><input type='text'  id='txbarea" + houcount + "'  name='txbarea" + houcount + "' value='" + drhou["hou_area"].ToString() + "' id='txbarea" + houcount + "' class='UnderlineButton1' style='width:45px' onblur='OnlyNumber(\"txbarea" + houcount + "\",\"建筑面积\");getHouseTotalArea()'></td>";
                OtherHouseHTML += "<td style='height: 37px; width: 87px;'><input type='text' name='txbowner" + houcount + "' value='" + drhou["hou_owner"].ToString() + "' class='UnderlineButton1' style='width:60px'></td>";
                OtherHouseHTML += "<td style='width: 129px; height: 37px;'><input type='text' name='txbownproof" + houcount + "' value='" + drhou["hou_ownproof"].ToString() + "' class='UnderlineButton1' style='width:100px'></td>";
                OtherHouseHTML += "<td style='width: 149px; height: 37px;'><input type='text' name='txbnature" + houcount + "' value='" + drhou["hou_nature"].ToString() + "' class='UnderlineButton1' style='width:100px'></td>";
                OtherHouseHTML += "<td style='width: 161px; height: 37px;'><input type='text' name='txbremark" + houcount + "' value='" + drhou["hou_remark"].ToString() + "' class='UnderlineButton1' style='width:150px'></td>";
                if (drhou["hou_addcounted"].ToString() == "1")
                    OtherHouseHTML += "<td style='width: 78px; height: 37px;'><input type='checkbox' checked name='ckbaddcount" + houcount + "' onclick='getTotal()'></td>";
                else
                    OtherHouseHTML += "<td style='width: 78px; height: 37px;'><input type='checkbox' name='ckbaddcount" + houcount + "' onclick='getTotal()'></td>";
                if (houcount != 0)
                    OtherHouseHTML += "<td style='width: 42px; height: 37px;'><input type='button' value='删除' name='del" + houcount + "' onclick='getHouseTotalArea();DelRowHousing(" + houcount + ");'/></td>";
                else
                    OtherHouseHTML += "<td style='width: 42px; height: 37px;'></td>";
                OtherHouseHTML += "</tr></table>";
            }
            houcount++;
            mmm++;
        }
        drhou.Close();

        rbldoc.SelectedIndex = rbldoc.Items.IndexOf(rbldoc.Items.FindByText(EditApply.apply_docname));
        // Response.Write(rbldoc.Items.FindByText(EditApply.apply_docname));
        show.InnerHtml = rbldoc.SelectedValue;


        //补贴 
        string noid = EditApply.apply_noid.ToString();
        SubsidyRecord subsidyrecord = new SubsidyRecord();
        subsidyrecord.GetNewestSubsidyRecordByApplyID(applyid);
        if (subsidyrecord.Adj_id > 0)
        {
            ckbsubsidy.Checked = true;
            ViewState["subsudy"] = subsidyrecord;
            string subhtml = "";
            subhtml = "补贴建筑面积为:" + subsidyrecord.Adj_nowarea;
            subhtml += "<br/>月补贴金额为:" + subsidyrecord.Adj_nowmoney;
            subsidy.InnerHtml = subhtml;
            this.submoney.Value = subsidyrecord.Adj_nowmoney;
            if (!string.IsNullOrEmpty(subsidyrecord.Adj_stoptime))
            {
                ddlyear1.SelectedValue = subsidyrecord.Adj_stoptime.Substring(0, 4);
                if (subsidyrecord.Adj_stoptime.Substring(4, 1) == "1")
                    ddlmonth1.SelectedValue = subsidyrecord.Adj_stoptime.Substring(4, 2);
                else
                    ddlmonth1.SelectedValue = subsidyrecord.Adj_stoptime.Substring(5, 1);
            }
        }
        ReduceRecord reducerecord = new ReduceRecord();
        reducerecord.GetNewestReduceRecordByApplyid(applyid);
        if (reducerecord.Adj_id > 0)
        {
            ckbreduce.Checked = true;
            ViewState["reduce"] = reducerecord;
            string redhtml = "";
            redhtml = "承&nbsp;&nbsp;租&nbsp;&nbsp;人&nbsp; ：<input type='text' name='username' class='UnderlineButton1'   value='" + reducerecord.Adj_renter + "'><br/>";
            redhtml += "承 租 地 址 ：<input type='text' name='address' class='UnderlineButton1'   value='" + reducerecord.Adj_rentaddress + "'><br/>";
            redhtml += "住房计租面积：<input type='text' name='area' class='UnderlineButton1'  value='" + reducerecord.Adj_nowarea + "'><br/>";
            redhtml += "核定月租金&nbsp;&nbsp;：<input type='text' name='checkmoney'   class='UnderlineButton1' value='" + reducerecord.Adj_nowmoney + "'><br/>";
            redhtml += "月减免租金额：<input type='text' name='reducemoney'  class='UnderlineButton1' value='" + reducerecord.Adj_nowreduce + "'><br/>";
            if (!string.IsNullOrEmpty(reducerecord.Adj_stoptime))
            {
                if (reducerecord.Adj_stoptime == "-1")
                    ddlyear2.SelectedValue = "无期";
                else
                {
                    ddlyear2.SelectedValue = reducerecord.Adj_stoptime.Substring(0, 4);
                    if (reducerecord.Adj_stoptime.Substring(4, 1) == "1")
                        ddlmonth2.SelectedValue = reducerecord.Adj_stoptime.Substring(4, 2);
                    else
                        ddlmonth2.SelectedValue = reducerecord.Adj_stoptime.Substring(5, 1);
                }

            }
            reduce.InnerHtml = redhtml;
        }
        else
            ckbreduce.Checked = false;
        KindRecord kindrecord = new KindRecord();
        kindrecord.GetNewestKindRecordByApplyid(applyid);
        if (kindrecord.Adj_id > 0)
        {
            ckbkind.Checked = true;
            ViewState["kind"] = kindrecord;
            //ckbkind.Enabled = false
            string kindhtml = "";
            kindhtml = "房屋座落：<input type='text' name='houseaddress' id='houseaddress'  class='UnderlineButton1' value='" + kindrecord.Adj_location + "'><br/>";
            kindhtml += "建筑面积：<input type='text' name='housearea'   class='UnderlineButton1' value='" + kindrecord.Adj_nowarea + "'><br/>";
            kindhtml += "使用面积：<input type='text' name='usearea'  class='UnderlineButton1' value='" + kindrecord.Adj_nowuserarea + "'><br/>";
            if (!string.IsNullOrEmpty(reducerecord.Adj_stoptime))
            {
                ddlyear3.SelectedValue = kindrecord.Adj_stoptime.Substring(0, 4);
                if (kindrecord.Adj_stoptime.Substring(4, 1) == "1")
                    ddlmonth3.SelectedValue = kindrecord.Adj_stoptime.Substring(4, 2);
                else
                    ddlmonth3.SelectedValue = kindrecord.Adj_stoptime.Substring(5, 1);
            }
            kind.InnerHtml = kindhtml;
        }
        else
            ckbkind.Checked = false;
    }
    protected void btnapply_Click(object sender, EventArgs e)
    {
        string noid = lblnoid.Text;
        string card = "";
        if (chkcard.Checked)
            card = txbcardnum.Text;
        else if (!chkmoney.Checked)
            WebHelper.Alert("请选择现金支付类型：打卡或现金支付");
        else
            card = "0";
        Apply apply = new Apply();
        apply.apply_noid = Convert.ToInt32(noid);
        apply.apply_name = txbname.Text;
        apply.apply_address = txbaddress.Text;
        apply.apply_phone = txbphone.Text;
        apply.apply_checkstate = 0;
        apply.apply_time = txbapplytime.Text;
        apply.apply_passed = 1;
        apply.apply_street = Session["UserStreet"].ToString();
        apply.apply_yearincome = float.Parse(this.Request["txbtotleincome"]);
        //Response.Write(this.Request["txbpeoplenum"]);
        //Response.End();
        apply.apply_peoplenum = Int32.Parse(this.Request["txbpeoplenum"]);
        apply.apply_avgincome = float.Parse(this.Request["txbavgincome"]);
        apply.apply_totlearea = float.Parse(this.Request["txbtotlearea"]);
        apply.apply_avgarea = float.Parse(this.Request["txbavgarea"]);
        apply.apply_totlepropertity = float.Parse(this.Request["txbtotleproperty"]);
        apply.apply_paybycard = card;
        apply.apply_docname = rbldoc.SelectedItem.Text;
        apply.AddSubsidyNum = float.Parse(this.tbAddSubsidyNum.Text);
        apply.CutSubsidyNum = float.Parse(this.tbCutSubsidyNum.Text);
        apply.apply_docnum = txbproofnum.Text;
        apply.EditNote = tbEditNote.Text;
        if (ddlyear4.SelectedItem.Value == "无期")
            apply.apply_docdate = "210901";
        else
            apply.apply_docdate = (Convert.ToInt32(ddlyear4.SelectedItem.Value) * 100 + Convert.ToInt32(ddlmonth4.SelectedItem.Value)).ToString();
        string longid = apply_longid.Text;

        //if (longid.Length < 8)
        //{
        //    StreetNumId strnum = new StreetNumId();
        //    longid = strnum.GenerateLongId(Session["UserStreet"].ToString(), longid);
        //    if (!string.IsNullOrEmpty(longid))
        //        apply.apply_longid = longid;
        //    else
        //        WebHelper.AlertAndClose("长编号已存在或街道不存在");
        //}
        //else
            apply.apply_longid = apply_longid.Text;
        apply.apply_updchecked = 1;
        if (cbisLengthenAYear.Checked)
            apply.isLengthenAYear = 1;
        else
            apply.isLengthenAYear = 0;

        if (this.ckbsubsidy.Checked)
            apply.IsSubsidy = 1;
        else
            apply.IsSubsidy = 0;

        if (this.ckbreduce.Checked)
            apply.IsReduce = 1;
        else
            apply.IsReduce = 0;
        if (this.ckbkind.Checked)
            apply.IsKind = 1;
        else
            apply.IsKind = 0;
        apply.EffectDate = (Convert.ToInt32(this.EffectDateYear.SelectedItem.Value) * 100 + Convert.ToInt32(this.EffectDateMonth.SelectedItem.Value));
        int succApplyid = apply.AddNewApply(apply);
        if (succApplyid > 0)
        {
            //添加Application
            Applicant applicant = new Applicant();
            applicant.app_applyid = succApplyid;
            applicant.app_noid = Int32.Parse(noid);
            applicant.app_title = txbapplytitle.Text;
            applicant.app_name = txbname.Text;
            applicant.app_marryed = ddlmarryed.SelectedValue;
            applicant.app_workunit = txbunit.Text;
            applicant.app_idcard = txbcard.Text;
            applicant.app_income = float.Parse(string.IsNullOrEmpty(txbincome.Text) ? "0" : txbincome.Text);
            applicant.EffectDate = (Convert.ToInt32(this.EffectDateYear.SelectedItem.Value) * 100 + Convert.ToInt32(this.EffectDateMonth.SelectedItem.Value));
            if (ckbispro.Checked == true)
                applicant.app_ispro = 1;
            else
                applicant.app_ispro = 0;
            applicant.AddNewApplicant(applicant);

            for (int i = 1; i < 10; i++)
            {
                short ckbiprovalue = 0;
                if (!string.IsNullOrEmpty(this.Request["txbapplytitle" + i]) && !string.IsNullOrEmpty(this.Request["txbname" + i]))
                {
                    if (this.Request["ckbispro" + i] == "on")
                        ckbiprovalue = 1;
                    string marryed = this.Request["ddlmarry" + i];
                    applicant = new Applicant();
                    applicant.app_applyid = succApplyid;
                    applicant.app_noid = Int32.Parse(noid);
                    applicant.app_title = this.Request["txbapplytitle" + i];
                    applicant.app_name = this.Request["txbname" + i];
                    applicant.app_marryed = marryed;
                    applicant.app_workunit = this.Request["txbunit" + i];
                    applicant.app_idcard = this.Request["txbcard" + i];
                    applicant.app_income = float.Parse(this.Request["txbincome" + i]);
                    applicant.app_ispro = ckbiprovalue;
                    applicant.EffectDate = (Convert.ToInt32(this.EffectDateYear.SelectedItem.Value) * 100 + Convert.ToInt32(this.EffectDateMonth.SelectedItem.Value));
                    applicant.AddNewApplicant(applicant);
                }
            }

            //添加享受类型，填入历史记录表
            string redname = "";
            string redaddress = "";
            string redarea = "";
            string redmoney = "";
            string redred = "";
            string kindarea = "";
            string kindusearea = "";
            string kindaddress = "";
            if (!string.IsNullOrEmpty(this.Request["username"]))
                redname = this.Request["username"];
            if (!string.IsNullOrEmpty(this.Request["address"]))
                redaddress = this.Request["address"];
            if (!string.IsNullOrEmpty(this.Request["area"]))
                redarea = this.Request["area"];
            if (!string.IsNullOrEmpty(this.Request["checkmoney"]))
                redmoney = this.Request["checkmoney"];
            if (!string.IsNullOrEmpty(this.Request["reducemoney"]))
                redred = this.Request["reducemoney"];
            if (!string.IsNullOrEmpty(this.Request["housearea"]))
                kindarea = this.Request["housearea"];
            if (!string.IsNullOrEmpty(this.Request["usearea"]))
                kindusearea = this.Request["usearea"];
            if (!string.IsNullOrEmpty(this.Request["houseaddress"]))
                kindaddress = this.Request["houseaddress"];
            if (ckbsubsidy.Checked)
            {
                SubsidyRecord subsidy = new SubsidyRecord();
                subsidy.Adj_noid = noid;
                subsidy.Adj_longid = "";
                subsidy.Adj_checked = "1";
                subsidy.Adj_nowarea = this.Request["subarea"];
                subsidy.Adj_nowmoney = this.Request["submoney"];
                subsidy.Adj_moneychange = this.Request["submoney"];
                subsidy.Adj_iscontinue = "0";
                //审核最终通过后设置下个月为起始时间
                subsidy.Adj_starttime = Convert.ToDateTime(txbapplytime.Text).AddMonths(1).ToString("yyyyMM");
                if (ddlyear1.SelectedValue == "无期")
                    subsidy.Adj_stoptime = "-1";
                else
                    subsidy.Adj_stoptime = (Convert.ToInt32(ddlyear1.SelectedItem.Value) * 100 + Convert.ToInt32(ddlmonth1.SelectedItem.Value)).ToString();
                subsidy.Adj_remark = "";
                subsidy.Adj_date = (DateTime.Now.Year * 100 + DateTime.Now.Month).ToString();
                subsidy.EffectDate = (Convert.ToInt32(this.EffectDateYear.SelectedItem.Value) * 100 + Convert.ToInt32(this.EffectDateMonth.SelectedItem.Value));
                subsidy.Applyid = succApplyid;
                subsidy.AddNewSubsidyRecord(subsidy);
            }
            if (ckbreduce.Checked)
            {
                ReduceRecord reduce = new ReduceRecord();
                reduce.Adj_longid = "";
                reduce.Adj_noid = noid;
                reduce.Adj_iscontinue = "0";
                reduce.Adj_checked = "1";
                reduce.Adj_date = (DateTime.Now.Year * 100 + DateTime.Now.Month).ToString();
                reduce.Adj_nowarea = redarea;
                reduce.Adj_nowmoney = redmoney;
                reduce.Adj_nowreduce = redred;
                reduce.Adj_reducechange = redred;
                reduce.Adj_remark = "";
                reduce.Adj_rentaddress = redaddress;
                reduce.Adj_renter = redname;
                reduce.Adj_starttime = Convert.ToDateTime(txbapplytime.Text).AddMonths(1).ToString("yyyyMM"); 
                if (ddlyear2.SelectedValue == "无期")
                    reduce.Adj_stoptime = "-1";
                else
                    reduce.Adj_stoptime = (Convert.ToInt32(ddlyear2.SelectedItem.Value) * 100 + Convert.ToInt32(ddlmonth2.SelectedItem.Value)).ToString();
                reduce.EffectDate = (Convert.ToInt32(this.EffectDateYear.SelectedItem.Value) * 100 + Convert.ToInt32(this.EffectDateMonth.SelectedItem.Value));
                reduce.Applyid = succApplyid;
                reduce.AddNewReduceRecord(reduce);
            }
            if (ckbkind.Checked)
            {
                KindRecord kind = new KindRecord();
                kind.Adj_checked = "1";
                kind.Adj_date = (DateTime.Now.Year * 100 + DateTime.Now.Month).ToString();
                kind.Adj_iscontinue = "0";
                kind.Adj_location = kindaddress;
                kind.Adj_longid = "";
                kind.Adj_noid = noid;
                kind.Adj_nowarea = kindarea;
                kind.Adj_nowuserarea = kindusearea;
                kind.Adj_remark = "";
                kind.Adj_starttime = Convert.ToDateTime(txbapplytime.Text).AddMonths(1).ToString("yyyyMM"); ;
                if (ddlyear3.SelectedValue == "无期")
                    kind.Adj_stoptime = "-1";
                else
                    kind.Adj_stoptime = (Convert.ToInt32(ddlyear3.SelectedItem.Value) * 100 + Convert.ToInt32(ddlmonth3.SelectedItem.Value)).ToString();
                kind.Adj_usechange = "0";
                kind.Applyid = succApplyid;
                kind.EffectDate = (Convert.ToInt32(this.EffectDateYear.SelectedItem.Value) * 100 + Convert.ToInt32(this.EffectDateMonth.SelectedItem.Value));
                kind.AddNewKindRecord(kind);
            }

            //添加财产情况
            string securitie = "0", estate = "0", device = "0", others = "0";
            if (!string.IsNullOrEmpty(txbsecuritie.Text))
                securitie = txbsecuritie.Text;
            if (!string.IsNullOrEmpty(txbestate.Text))
                estate = txbestate.Text;
            if (!string.IsNullOrEmpty(txbdevice.Text))
                device = txbdevice.Text;
            if (!string.IsNullOrEmpty(txbothers.Text))
                others = txbothers.Text;
            Property property = new Property();
            property.pro_applyid = succApplyid;
            property.pro_noid = Int32.Parse(noid);
            property.pro_securitie = float.Parse(securitie);
            property.pro_estat = float.Parse(estate);
            property.pro_device = float.Parse(device);
            property.pro_other = float.Parse(others);
            property.EffectDate = (Convert.ToInt32(this.EffectDateYear.SelectedItem.Value) * 100 + Convert.ToInt32(this.EffectDateMonth.SelectedItem.Value));
            property.AddNewProperty(property);

            //添加住房情况
            HouseSituation house = new HouseSituation();
            if (!string.IsNullOrEmpty(txblocal.Text) || !string.IsNullOrEmpty(txbarea.Text) || !string.IsNullOrEmpty(txbowner.Text))
            {
                house.hou_applyid = succApplyid;
                house.hou_noid = Int32.Parse(noid);
                house.hou_address = txblocal.Text;
                house.hou_area = float.Parse(txbarea.Text);
                house.hou_owner = txbowner.Text;
                house.hou_ownproof = txbownproof.Text;
                house.hou_nature = txbnature.Text;
                house.hou_remark = txbremark.Text;
                if (ckbaddcount.Checked == true)
                    house.hou_addcounted = "1";
                else
                    house.hou_addcounted = "0";
                house.EffectDate = (Convert.ToInt32(this.EffectDateYear.SelectedItem.Value) * 100 + Convert.ToInt32(this.EffectDateMonth.SelectedItem.Value));
                house.AddNewHouseSituation(house);
            }
            for (int i = 1; i < 10; i++)
            {
                string ckbaddcountvalue = "0";
                if (!string.IsNullOrEmpty(this.Request["txblocal" + i]) || !string.IsNullOrEmpty(this.Request["txbarea" + i]) || !string.IsNullOrEmpty(this.Request["txbowner" + i]))
                {
                    if (this.Request["ckbaddcount" + i] == "on")
                        ckbaddcountvalue = "1";
                    house = new HouseSituation();
                    house.hou_applyid = succApplyid;
                    house.hou_noid = Convert.ToInt32(noid);
                    house.hou_address = this.Request["txblocal" + i];
                    house.hou_area = float.Parse(this.Request["txbarea" + i]);
                    house.hou_owner = this.Request["txbowner" + i];
                    house.hou_ownproof = this.Request["txbownproof" + i];
                    house.hou_nature = this.Request["txbnature" + i];
                    house.hou_remark = this.Request["txbremark" + i];
                    house.hou_addcounted = ckbaddcountvalue;
                    house.EffectDate = (Convert.ToInt32(this.EffectDateYear.SelectedItem.Value) * 100 + Convert.ToInt32(this.EffectDateMonth.SelectedItem.Value));
                    house.AddNewHouseSituation(house);
                }
            }
            Admissibility admissibility = new Admissibility();
            admissibility.SetAdmissibilityAdded(noid);
            WebHelper.AlertAndCloseThenRefreshLastPage("录入成功！");
        }
        else
            WebHelper.Alert("数据录入失败，请重新操作!");
    }
    protected void BindDate()
    {
        int year = Convert.ToInt32(DateTime.Now.Year.ToString());
        for (int i = year; i < year + 3; i++)
        {
            ddlyear1.Items.Add(i.ToString());
            ddlyear2.Items.Add(i.ToString());
            ddlyear3.Items.Add(i.ToString());
            ddlyear4.Items.Add(i.ToString());
            this.EffectDateYear.Items.Add(i.ToString());


        }
        ddlyear1.Items.Add("无期");
        ddlyear2.Items.Add("无期");
        ddlyear3.Items.Add("无期");
        ddlyear4.Items.Add("无期");
    }
    protected void txbunit_TextChanged(object sender, EventArgs e)
    {

    }

    //Edit CLick
    protected void btnedit_Click(object sender, EventArgs e)
    {
        
        
        Apply applyView = (Apply)ViewState["apply"];
        applyView.EffectDate = (Convert.ToInt32(this.EffectDateYear.SelectedItem.Value) * 100 + Convert.ToInt32(this.EffectDateMonth.SelectedItem.Value));



        //edit does not change the EffectDate
  
         //--------------------APPLY---------------------------------
        string applyid =Request.QueryString["applyid"].ToString();
        string noid = lblnoid.Text;
        string card = "";
        if (chkcard.Checked)
            card = txbcardnum.Text;
        else if (!chkmoney.Checked)
            WebHelper.Alert("请选择现金支付类型：打卡或现金支付");
        else
            card = "0";
        EditApply = new Apply();
        EditApply.apply_id = int.Parse(applyid);
        EditApply.apply_noid = Convert.ToInt32(noid);
        EditApply.apply_name = txbname.Text;
        EditApply.apply_address = txbaddress.Text;
        EditApply.apply_phone = txbphone.Text;
        EditApply.apply_checkstate = 0;
        EditApply.apply_time = txbapplytime.Text;
        EditApply.apply_passed = applyView.apply_passed;
        EditApply.apply_updchecked = applyView.apply_updchecked;
        EditApply.apply_street = Session["UserStreet"].ToString();
        EditApply.apply_yearincome = float.Parse(this.Request["txbtotleincome"]);
        EditApply.apply_peoplenum = Int32.Parse(this.Request["txbpeoplenum"]);
        EditApply.apply_avgincome = float.Parse(this.Request["txbavgincome"]);
        EditApply.apply_totlearea = float.Parse(this.Request["txbtotlearea"]);
        EditApply.apply_avgarea = float.Parse(this.Request["txbavgarea"]);
        EditApply.apply_totlepropertity = float.Parse(this.Request["txbtotleproperty"]);
        EditApply.apply_paybycard = card;
        EditApply.apply_docname = rbldoc.SelectedItem.Text;
        EditApply.apply_docnum = txbproofnum.Text;
        EditApply.EffectDate = applyView.EffectDate;
        EditApply.EditNote = tbEditNote.Text;
        EditApply.apply_docdate = (Convert.ToInt32(ddlyear4.SelectedItem.Value) * 100 + Convert.ToInt32(ddlmonth4.SelectedItem.Value)).ToString();
        string longid = apply_longid.Text;
        EditApply.apply_longid = longid;
        //if (longid.Length < 8)
        //{
        //    StreetNumId strnum = new StreetNumId();
        //    longid = strnum.GenerateLongId(Session["UserStreet"].ToString(), longid);
        //    if (!string.IsNullOrEmpty(longid))
        //        EditApply.apply_longid = longid;
        //    else
        //        WebHelper.AlertAndClose("长编号已存在或街道不存在");
        //}
        EditApply.apply_longid = longid;
        if (cbisLengthenAYear.Checked)
            EditApply.isLengthenAYear = 1;

        else
            EditApply.isLengthenAYear = 0;

        if (this.ckbsubsidy.Checked)
            EditApply.IsSubsidy = 1;
        else
            EditApply.IsSubsidy = 0;

        if (this.ckbreduce.Checked)
            EditApply.IsReduce = 1;
        else
            EditApply.IsReduce = 0;
        if (this.ckbkind.Checked)
            EditApply.IsKind = 1;
        else
            EditApply.IsKind = 0;
       
       
        if (cbisLengthenAYear.Checked)
            EditApply.isLengthenAYear = 1;
        else
            EditApply.isLengthenAYear = 0;

        if (Request.QueryString["thetype"] != null && Request.QueryString["thetype"]== "edit")
        {
            int delApplyFrom = EditApply.DeleteAApplyByApplyId(int.Parse(applyid));//删除本月本人
            int delApplyTo = EditApply.DeleteAApplyByNoidEffectDate(EditApply.apply_noid, applyView.EffectDate);//删除调整后的那月那人 
        }
        if (Request.QueryString["thetype"] != null && Request.QueryString["thetype"] == "change")
        {
            int delApply = EditApply.DeleteAApplyByNoidEffectDate(EditApply.apply_noid, applyView.EffectDate);//删除调整后的那月那人 
        }

        EditApply.AddSubsidyNum = float.Parse(tbAddSubsidyNum.Text);
        EditApply.CutSubsidyNum = float.Parse(tbCutSubsidyNum.Text);
        int succApply = EditApply.AddNewApply(EditApply);

        //--------------------Application---------------------------------
        if (succApply > 0)
        {
            //修改Application
            Applicant applicant = new Applicant();
            //删除该noid
            //applicant.DeleteApplicantByAppApplyid(applyid);
            applicant.app_applyid = succApply;
            applicant.app_noid = Int32.Parse(noid);
            applicant.app_title = txbapplytitle.Text;
            applicant.app_name = txbname.Text;
            applicant.app_marryed = ddlmarryed.SelectedValue;
            applicant.app_workunit = txbunit.Text;
            applicant.app_idcard = txbcard.Text;
            applicant.app_income = float.Parse(string.IsNullOrEmpty(txbincome.Text) ? "0" : txbincome.Text);
            if (ckbispro.Checked == true)
                applicant.app_ispro = 1;
            else
                applicant.app_ispro = 0;
            applicant.EffectDate = applyView.EffectDate;
            applicant.AddNewApplicant(applicant);

            for (int i = 1; i < 10; i++)
            {
                short ckbiprovalue = 0;
                if (!string.IsNullOrEmpty(this.Request["txbapplytitle" + i]) && !string.IsNullOrEmpty(this.Request["txbname" + i]))
                {
                    if (this.Request["ckbispro" + i] == "on")
                        ckbiprovalue = 1;
                    string marryed = this.Request["ddlmarry" + i];
                    applicant = new Applicant();
                    applicant.app_applyid = succApply;
                    applicant.app_noid = Int32.Parse(noid);
                    applicant.app_title = this.Request["txbapplytitle" + i];
                    applicant.app_name = this.Request["txbname" + i];
                    applicant.app_marryed = marryed;
                    applicant.app_workunit = this.Request["txbunit" + i];
                    applicant.app_idcard = this.Request["txbcard" + i];
                    applicant.app_income = float.Parse(this.Request["txbincome" + i]);
                    applicant.app_ispro = ckbiprovalue;
                    applicant.EffectDate = applyView.EffectDate;
                    applicant.AddNewApplicant(applicant);
                }
            }

            //--------------------SubsidyRecord---------------------------------
            string redname = "";
            string redaddress = "";
            string redarea = "";
            string redmoney = "";
            string redred = "";
            string kindarea = "";
            string kindusearea = "";
            string kindaddress = "";
            if (!string.IsNullOrEmpty(this.Request["username"]))
                redname = this.Request["username"];
            if (!string.IsNullOrEmpty(this.Request["address"]))
                redaddress = this.Request["address"];
            if (!string.IsNullOrEmpty(this.Request["area"]))
                redarea = this.Request["area"];
            if (!string.IsNullOrEmpty(this.Request["checkmoney"]))
                redmoney = this.Request["checkmoney"];
            if (!string.IsNullOrEmpty(this.Request["reducemoney"]))
                redred = this.Request["reducemoney"];
            if (!string.IsNullOrEmpty(this.Request["housearea"]))
                kindarea = this.Request["housearea"];
            if (!string.IsNullOrEmpty(this.Request["usearea"]))
                kindusearea = this.Request["usearea"];
            if (!string.IsNullOrEmpty(this.Request["houseaddress"]))
                kindaddress = this.Request["houseaddress"];
            if (ckbsubsidy.Checked)
            {
                SubsidyRecord subrecord = (SubsidyRecord)ViewState["subsidy"];
                SubsidyRecord subsidy = new SubsidyRecord();
                subsidy.Adj_noid = noid;
                subsidy.Adj_longid = apply_longid.Text;
                subsidy.Adj_checked = "1";
                subsidy.Adj_nowarea = this.Request["subarea"];
                subsidy.Adj_nowmoney = this.Request["submoney"];
                subsidy.Adj_moneychange = SubsidyRecord.getAdj_moneychange(succApply.ToString(), applyView.EffectDate.ToString(), this.Request["submoney"]);
                subsidy.Adj_iscontinue ="0";
                subsidy.Adj_starttime = Convert.ToDateTime(txbapplytime.Text).AddMonths(1).ToString("yyyyMM");
                subsidy.Adj_stoptime = (Convert.ToInt32(ddlyear1.SelectedItem.Value) * 100 + Convert.ToInt32(ddlmonth1.SelectedItem.Value)).ToString(); 
                subsidy.EffectDate = applyView.EffectDate;
                if (ddlyear1.SelectedValue == "无期")
                    subsidy.Adj_stoptime = "-1";
                else
                    subsidy.Adj_stoptime = (Convert.ToInt32(ddlyear1.SelectedItem.Value) * 100 + Convert.ToInt32(ddlmonth1.SelectedItem.Value)).ToString();
                if(subrecord!=null)
                     subsidy.Adj_remark = subrecord.Adj_remark;
                subsidy.Adj_date = (DateTime.Now.Year * 100 + DateTime.Now.Month).ToString();
                subsidy.Applyid = succApply;
                subsidy.EffectDate =applyView.EffectDate;
              //  SubsidyRecord.DeleteASubsidyRecordByApplyid(int.Parse(applyid));//delete
                subsidy.AddNewSubsidyRecord(subsidy);//add
            }
            else
            {
                SubsidyRecord.DeleteASubsidyRecordByApplyid(int.Parse(applyid));
            }
            //--------------------ReduceRecord---------------------------------
            if (ckbreduce.Checked)
            {
                ReduceRecord reduce = new ReduceRecord();
                ReduceRecord redrecord = (ReduceRecord)ViewState["reduce"];
                reduce.Adj_longid = apply_longid.Text;
                reduce.Adj_noid = noid;
                reduce.Adj_iscontinue = "0";
                reduce.Adj_checked ="1";
                reduce.Adj_date = (DateTime.Now.Year * 100 + DateTime.Now.Month).ToString();
                reduce.Adj_nowarea = redarea;
                reduce.Adj_nowmoney = redmoney;
                reduce.Adj_nowreduce = redred;
                reduce.Adj_reducechange = ReduceRecord.getmoneychange(succApply.ToString(), applyView.EffectDate.ToString(), redred);
		if(redrecord!=null)
                     redrecord.Adj_remark = redrecord.Adj_remark;
                reduce.Adj_rentaddress = redaddress;
                reduce.Adj_renter = redname;
                reduce.Adj_starttime =  Convert.ToDateTime(txbapplytime.Text).AddMonths(1).ToString("yyyyMM");
                if (ddlyear2.SelectedValue == "无期")
                    reduce.Adj_stoptime = "-1";
                else
                    reduce.Adj_stoptime = (Convert.ToInt32(ddlyear2.SelectedItem.Value) * 100 + Convert.ToInt32(ddlmonth2.SelectedItem.Value)).ToString();
                reduce.Applyid = succApply;
                reduce.EffectDate =applyView.EffectDate;
              //  ReduceRecord.DeleteAReduceRecordByApplyid(applyid.ToString());
                reduce.AddNewReduceRecord(reduce);
            }
            else
            {
                ReduceRecord.DeleteAReduceRecordByApplyid(applyid.ToString());

            }
            //--------------------KindRecord---------------------------------
            if (ckbkind.Checked)
            {
                KindRecord kind = new KindRecord();
                KindRecord kindrecord = (KindRecord)ViewState["kind"];
                kind.Adj_checked ="1";
                kind.Adj_date = (DateTime.Now.Year * 100 + DateTime.Now.Month).ToString();
                kind.Adj_iscontinue ="0";
                if(Request.QueryString["houseaddress"]!=null)
                   kind.Adj_location = Request.QueryString["houseaddress"];
               // Response.Write(Request.QueryString["houseaddress"]);
               // Response.End();
                kind.Adj_longid = apply_longid.Text;
                kind.Adj_noid = noid;
                kind.Adj_nowarea = kindarea;
                kind.Adj_nowuserarea = kindusearea;
                if(kindrecord!=null)
                    kind.Adj_remark = kindrecord.Adj_remark;
                kind.Adj_starttime = Convert.ToDateTime(txbapplytime.Text).AddMonths(1).ToString("yyyyMM");
                if (ddlyear3.SelectedValue == "无期")
                    kind.Adj_stoptime = "-1";
                else
                    kind.Adj_stoptime = (Convert.ToInt32(ddlyear3.SelectedItem.Value) * 100 + Convert.ToInt32(ddlmonth3.SelectedItem.Value)).ToString();

                kind.Adj_usechange = KindRecord.getmoneychange(succApply.ToString(), applyView.EffectDate.ToString(), kindusearea);
                kind.Applyid = succApply;
                kind.EffectDate = applyView.EffectDate;
              //  KindRecord.DeleteAKindRecordByApplyid(applyid.ToString());
                kind.AddNewKindRecord(kind);
            }
            else
            {
                KindRecord.DeleteAKindRecordByApplyid(applyid.ToString());
            }

            //--------------------property---------------------------------
            string securitie = "0", estate = "0", device = "0", others = "0";
            if (!string.IsNullOrEmpty(txbsecuritie.Text))
                securitie = txbsecuritie.Text;
            if (!string.IsNullOrEmpty(txbestate.Text))
                estate = txbestate.Text;
            if (!string.IsNullOrEmpty(txbdevice.Text))
                device = txbdevice.Text;
            if (!string.IsNullOrEmpty(txbothers.Text))
                others = txbothers.Text;
            Property property = new Property();
            property.pro_applyid = succApply;
            property.pro_noid = int.Parse(noid);
            property.pro_securitie = float.Parse(securitie);
            property.pro_estat = float.Parse(estate);
            property.pro_device = float.Parse(device);
            property.pro_other = float.Parse(others);
            property.EffectDate = applyView.EffectDate;
            property.AddNewProperty(property);

            //--------------------Housing---------------------------------
            HouseSituation house = new HouseSituation();
            if (!string.IsNullOrEmpty(txblocal.Text) && !string.IsNullOrEmpty(txbarea.Text) && !string.IsNullOrEmpty(txbowner.Text))
            {
                house.hou_applyid = succApply;
                house.hou_noid = int.Parse(noid);
                house.hou_address = txblocal.Text;
                house.hou_area = float.Parse(txbarea.Text);
                house.hou_owner = txbowner.Text;
                house.hou_ownproof = txbownproof.Text;
                house.hou_nature = txbnature.Text;
                house.hou_remark = txbremark.Text;
                
                if (ckbaddcount.Checked == true)
                    house.hou_addcounted = "1";
                else
                    house.hou_addcounted = "0";
                house.Applyid = int.Parse(applyid);
                house.EffectDate = applyView.EffectDate;
                //house.DeleteHouseSituationByApplyid(applyid.ToString());
                house.AddNewHouseSituation(house);
            }
            for (int i = 1; i < 10; i++)
            {
                string ckbaddcountvalue = "0";
                if (!string.IsNullOrEmpty(this.Request["txblocal" + i]) && !string.IsNullOrEmpty(this.Request["txbarea" + i]) && !string.IsNullOrEmpty(this.Request["txbowner" + i]))
                {
                    if (this.Request["ckbaddcount" + i] == "on")
                        ckbaddcountvalue = "1";
                    house = new HouseSituation();
                    house.hou_applyid = succApply;
                    house.hou_noid = Convert.ToInt32(lblnoid.Text);
                    house.hou_address = this.Request["txblocal" + i];
                    house.hou_area = float.Parse(this.Request["txbarea" + i]);
                    house.hou_owner = this.Request["txbowner" + i];
                    house.hou_ownproof = this.Request["txbownproof" + i];
                    house.hou_nature = this.Request["txbnature" + i];
                    house.hou_remark = this.Request["txbremark" + i];
                    house.hou_addcounted = ckbaddcountvalue;
                    house.EffectDate = applyView.EffectDate;
                    house.AddNewHouseSituation(house);
                }
            }
            WebHelper.AlertAndCloseThenRefreshLastPage("修改成功！");
        }
        else
            WebHelper.Alert("数据录入失败，请重新操作!");
    }
    protected void btnchange_Click(object sender, EventArgs e)
    {
        //change 
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (lblid.Text.Length > 0)
        {
            new Apply().DeleteAApplyByApplyId(int.Parse(lblid.Text));
            WebHelper.AlertAndCloseThenRefreshLastPage("删除成功");
        }
        else
        {
            WebHelper.AlertAndCloseThenRefreshLastPage("applyid参数有误");
        }
    }
}
